<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <script>
        /*      从以下学员名单中随机选出4个学员：

                    var arr = ["罗彬","熊博文","黄鸿鹏","李茂林","陈汝威","麦子彬","王光彩","邓君","卢儒山","张境锋",
                    "蔡泽钏","周圆","郑华","温俊林","梁自立","袁国文"]；

                    注意：不要有重复的学员 */

        // 学员名单
        var arr = ["罗彬", "熊博文", "黄鸿鹏", "李茂林", "陈汝威", "麦子彬", "王光彩", "邓君", "卢儒山", "张境锋",
            "蔡泽钏", "周圆", "郑华", "温俊林", "梁自立", "袁国文"
        ];

        // 选出的名单
        let select_arr = [];
        //随机数的数组
        let randoms = [];

        while (true) {
            // let randoms = [];
            let Exist = false;
            let random = get_random(arr.length - 1, 0);
            for (let i = 0; i < randoms.length; i++) {
                // 如果生成的随机数与随机数组中的值重复,就Exist = true;
                if (random == randoms[i]) {
                    Exist = true;
                    break;
                }
            }
            // 如果没有重复就追加随机数的数组
            if (!Exist) {
                randoms.push(random);
            }
            // 当随机的数组的长度为4结束while循环
            if (randoms.length == 4) {
                break;
            }
        }
        // console.log(randoms);
        // 生成随机数函数 max 最大值 min 最小值
        function get_random(max, min) {
            return Math.floor(Math.random() * (max - min + 1) + min);
        }
        // 遍历随机数的数组
        for (let i = 0; i < randoms.length; i++) {
            select_arr.push(arr[randoms[i]]);
        }

        console.log(select_arr);
    </script>
</body>

</html>